<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>保险录单--汽车金融-乘用车</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<form id="insPlcBscInfo_form">
    <div class="fieldset1 tabel_col clearFix">
        <div class="caption">
            <span class="title">保单基本信息</span>
        </div>
        <div class="fieldBox col_33">
            <div class="label">保险公司</div>
            <div class="field">
                <input name="insCompId" id="insCompId" data-value="${insPlcBscInfoVO.insCompId}"
                       placeholder="请选择" ltype="combobox" validate="{required:true}">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_33">
            <div class="label">保单起止日期</div>
            <div class="field">
                <input ligerui="width: 87" name="plcBgTm" id="plcBgTm" type="text" class="ui-datepicker"
                       value="${insPlcBscInfoVO.plcBgTms}" validate="{required:true}">
                <input ligerui="width: 87" name="plcEndTm" id="plcEndTm" type="text" class="ui-datepicker"
                       value="${insPlcBscInfoVO.plcEndTms}" validate="{required:true}">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_33">
            <div class="label">保费总金额</div>
            <div class="field">
                <input name="insTtlFee" id="insTtlFee" type="text" class="ui-textbox"
                       value="${insPlcBscInfoVO.insTtlFeeDb}" ligerui="width: 178" data-tofix="2"
                       validate="{required:true,number:true}">
                <span class="requiredSymbol">*</span>

            </div>
        </div>
        <div class="fieldBox col_33">
            <div class="label">被保险人</div>
            <div class="field">
                <input name="insPerNm" id="insPerNm" type="text" class="ui-textbox" value="${insPlcBscInfoVO.insPerNm}"
                       validate="{required:false,maxlength:40}">
            </div>
        </div>
        <div class="fieldBox col_33">
            <div class="label">被保险人证件号码</div>
            <div class="field">
                <input name="insPerCretNo" id="insPerCretNo" type="text" class="ui-textbox"
                       value="${insPlcBscInfoVO.insPerCretNo}" validate="{required:false,maxlength:20}">
            </div>
        </div>
        <div class="fieldBox col_33">
            <div class="label">第一受益人</div>
            <div class="field">
                <input name="fstPer" id="fstPer" data-value="${insPlcBscInfoVO.fstPer}" value="${insPlcBscInfoVO.fstPer}"
                       class="ui-textbox" validate="{maxlength:45}">
            </div>
        </div>
        <%--<div class="fieldBox col_33">
            <div class="label">第一受益人</div>
            <div class="field">
                <input name="fstPer" id="fstPer" data-value="${insPlcBscInfoVO.fstPer}" value="${insPlcBscInfoVO.fstPer}" type="text"
                       placeholder="请选择" ltype="combobox">
            </div>
        </div>--%>
        <div class="fieldBox col_100">
            <div class="label">特别说明</div>
            <div class="field">
                <textarea name="plcRem" id="plcRem" class="ui-textarea l-textarea" cols="130" rows="3"
                          style="width: 97%;"
                          value="${insPlcBscInfoVO.plcRem}"
                          validate="{required:false,maxlength:200}">${insPlcBscInfoVO.plcRem}</textarea>
            </div>
        </div>

        <%--<input type="text" style="display: block;" id="insPlcBscInfoId" name="insPlcBscInfoId">--%>
        <input type="text" name="plcExpCd" id="plcExpCd" style="display: none;" value="1">
    </div>

    <div class="btnsBox">
        <span id="saveInsPlcBscInfo_Btn" class="sq-button sq-button-round">保存</span>
        <span id="back_Btn" class="sq-button sq-button-round">返回</span>
        <input type="reset" id="resetBtn" class="l-button l-button-reset Hide">
    </div>

    <div class="fieldset1 tabel_col tabel_col_s clearFix">
        <div class="sqPanel">
            <div class="sqPanel_head inL">
                <span>保单附件</span>
            </div>
            <div class="sqPanel_body">
                <div id="plcFileCfgGrid" class="sq-grid"></div>
            </div>
        </div>

        <div class="sqPanel">
            <div class="sqPanel_head inL">
                <span>保单产品信息</span>
            </div>
            <div class="fieldBox col_100">
                <div id="plcPrdGrid" class="sq-grid"></div>
            </div>
        </div>
    </div>

</form>

<script type="text/javascript" src="<%=path%>/resource/lib/plugins/ajaxfileupload.js"></script>
<script>
    var plcPrdGrid,plcFileCfgGrid, form;
    var insPlcBscInfoId;
    $(function () {
        insPlcBscInfoId='${insPlcBscInfoVO.id}';
        var ctrlKey='${ctrlKey}';//控制上传

        $("#insCompId").ligerComboBox({
            valueField: 'key',
            textField: 'value',
            autocomplete: function (e) {
                filter_autoComboboxData(e.key, this);
                e.show();
            },
        });
        /*$("#plcExpCd").ligerComboBox({
            valueField: 'key',
            textField: 'value',
        });*/

        /*$("#fstPer").ligerComboBox({
            data: ${fstPerTypCdList},
            valueField: 'key',
            textField: 'value'
        });*/

        form = $("#insPlcBscInfo_form").ligerForm({
            validate: true
        });

        liger.get("insCompId").setData(${insCompList});
        liger.get("insCompId").updateStyle();
        //liger.get("plcExpCd").setData(${plcExpCdList});

        //保单产品
        plcPrdGrid = $("#plcPrdGrid").ligerGrid({
            url: '<%=path%>/insurance/insPlcBscInfo/initPlcPrdList.do?prjPrdDtlId=${prjPrdDtlId}',
            method: 'get',
            columns: [
                {display: '产品名称', name: 'prdNm', minWidth: 100, align: 'center'},
                {display: '产品型号', name: 'prdMdl', width: 100, align: 'left'},
                {display: '厂商', name: 'mfrNm', minWidth: 100, align: 'left'},
                {display: '供应商', name: 'splNm', minWidth: 100, align: 'left'},
                {display: '发动机编号', name: 'engMdl', width: 100, align: 'left'},
                {display: '车架号', name: 'vinNo', width: 100, align: 'left'},
                {display: '底盘号', name: 'chsNo', width: 100, align: 'left'},
                {
                    display: '单价', name: 'prdAmt', width: 90, align: 'right',
                    render: function (rowdata, rowindex, value) {
                        return '&yen;' + FormatMoney(rowdata.prdAmt / 100);
                    }
                },
                {
                    display: '合格证号', name: 'certNo', minWidth: 100, align: 'left',
                    render: function (rowdata, rowindex, value) {
                        if (value) {
                            return '<a href="javascript:;" onclick="detailBtn(' + rowdata.actPrdId + ',' + rowdata.prjPrdDtlId + ')">' + rowdata.certNo + '</a>';
                        }
                    }
                },
                {display: '客户名称', name: 'cstNm', width: 100, align: 'left'},
            ],
            usePager: false,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            heightDiff: -2,
            allowUnSelectRow: true,
            alternatingRow: false
        });

        //保单附件
        plcFileCfgGrid = $("#plcFileCfgGrid").ligerGrid({
            url: '<%=path%>/insurance/insPlcBscInfo/initPlcCfgFileList.do',
            method: 'get',
            parms:{"id":insPlcBscInfoId,"cfgCd":"INS002,PRJ018","buOrgCd":"${buOrgCd}"},
            columns: [
                {display: '资料名称', name: 'datNm', minWidth: 100, align: 'left', enabledSort: false},
                {display: '上传文件名称', name: 'fileNm', minWidth: 100, align: 'left', enabledSort: false,
                    render:function(rowdata,rowindex,value){
                        if(value){
                            var h;
                            h='<a href="javascript:uploadFileByUrl(';
                            h+="'"+rowdata.filePath+"'";
                            h+=",'"+rowdata.fileNm+"'";
                            h+=')">'+rowdata.fileNm+'</a>'
                            return h;
                        }
                    }
                },
                {display: '上传时间', name: 'crtTm', minWidth: 100, align: 'left', enabledSort: false,render:renderDate},
                /*{display: '状态', name: 'audStsCdNm', width: 100, enabledSort: false},*/
                {display: '操作', name: '', minWidth: 100, align: 'left', enabledSort: false,
                    render:function(rowdata,rowindex,value){
                        var h='';
                        if(ctrlKey==1){
                            h+='<span class="sq-button sq-button-round fileupload-button">上传<input type="file" id="fileup_'+rowdata.cfgCd+'_'+rowdata.cfgDtlCd+'" multiple name="fileup_'+rowdata.cfgCd+'_'+rowdata.cfgDtlCd+'"' +
                                ' class="fileupload-input" onchange="onChangefile_multi(event,\''+rowdata.cfgCd+'\',\''+rowdata.cfgDtlCd+'\',\''+rowdata.orgCd+'\')"></span>';
                            if(rowdata.fileId && rowdata.audStsCd!=1) {
                                h+='<span class="sq-button sq-button-round fileupload-button" onclick="delFile(event,' + rowdata.fileId + ');">删除</span>';
                            }
                        }
                        return h;
                    }
                },
            ],
            root: 'rows',
            hideLoadButton : true,
            width: '100%',
            height: '100%',
            isScroll: false,
            rownumbers:true,  //显示序号
            checkbox: false,
            allowUnSelectRow:true,
            alternatingRow: false,
            frozen: false,
            usePager: false,
            onAfterShowData: function (){
                $('#plcFileCfgGrid').rowspan('datNm');
            }
        });

        $("#pageloading").hide();

        /*保存保单*/
        $("#saveInsPlcBscInfo_Btn").click(function (event) {
            if (!form.valid()) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
                return false; //验证不通过，不执行以下代码
            }
            var data = form.getData();
            $.ligerDialog.hide();
            var _url;
            if (!insPlcBscInfoId) {//新增
                _url = '<%=path%>/insurance/insPlcBscInfo/add.do';
                var prdData = plcPrdGrid.getData();
                if(prdData.length>0){
                    data['paySchId']=prdData[0].paySchId;
                    data['paySchNo']=prdData[0].paySchNo;
                    data['prjPrdDtlId']=prdData[0].prjPrdDtlId;
                    data['prjId']=prdData[0].prjId;
                    data['cstId']=prdData[0].cstId;
                    data['cstNm']=prdData[0].cstNm;
                    data['cstMgrId']=prdData[0].cstMgrId;
                    data['cstMgrNm']=prdData[0].cstMgrNm;
                    data['buOrgCd']=prdData[0].buOrgCd;
                    data['cstMgrOrgCd']=prdData[0].cstMgrOrgCd;
                    data['contNo']=prdData[0].lsCntNo;
                }
            } else {//修改
                _url = '<%=path%>/insurance/insPlcBscInfo/modify.do?id=' + insPlcBscInfoId;
            }

            var wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: data,
                url: _url,
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        if(insPlcBscInfoId ==""||insPlcBscInfoId.length==0){
                            insPlcBscInfoId = msg.data;
                            plcFileCfgGrid.removeParm("id");
                            plcFileCfgGrid.setParm("id",msg.data);
                        }
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        });

        //返回
        $("#back_Btn").click(function () {
            //回调刷新列表
            var callback = GET_W2Wcallback();
            if(callback){
                callback();
            }
            Remove_navTab();
        });

    });

    //删除文件
    function delFile(event,_fileId){
        var wait_dialog;
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {'fileId':_fileId},
            url: '<%=path%>/insurance/insPlcBscInfo/removePlcFile.do',
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success: function (msg) {
                wait_dialog.close();
                if (msg.success == 1) {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                    event.stopPropagation();
                    plcFileCfgGrid.reload();
                }else{
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }

    function onChangefile_multi(e,cfgCd,cfgDtlCd,orgCd) {
        if(insPlcBscInfoId ==""||insPlcBscInfoId.length==0){
            $.ligerDialog.SQalert({content: "请先保存保单信息", SQ_type: "warning"});
            return;
        }
        var wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
        $.ajaxFileUpload({
            url: '<%=path%>/system/sysulfilesrec/upload.do',
            secureuri: false,
            fileElementId: e.target.id,  //这里不在是以前的id了，要写成数组的形式！
            dataType: 'json',
            data: {filePath: "insPlcInfo"},
            success: function (msg) {
                if (msg.success == 1) {
                    $.ajax({
                        type: 'post',
                        dataType: 'json',
                        data: {'fileParams':JSON.stringify(msg.data),'id':insPlcBscInfoId,'cfgCd':cfgCd,'cfgDtlCd':cfgDtlCd,"orgCd":orgCd},
                        url: '<%=path%>/insurance/insPlcBscInfo/uploadPlcFile.do',
                        success: function (msg) {
                            wait_dialog.close();
                            if (msg.success == 1) {
                                plcFileCfgGrid.reload();
                            }else{
                                $.ligerDialog.SQalert({content: "资料上传失败", SQ_type: "error"});
                            }
                        }
                    });
                } else {
                    wait_dialog.close();
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            },
        });

    };

    //合格证详情
    function detailBtn(id,dtlId){
        Add_navTab('tab_prj_prd_veh_info_detail'+id,'合格证详情','<%=path%>/project/prjprdvehinfo/toDetailPage.do?detailFlag=true&&id='+id+'&&dtlId='+dtlId);
    }

    function uploadFileByUrl(_url,_name){
        if(SQ.regs.img.test(_name)){
            window.__ImgSrc = _url;
            window.__ImgTit = _name;
            window.open('<%=path%>/project/prjbscinfo/imgWinOpen.do', '', 'location=yes, width=800, height=600');
        }else{
            window.open(_url);
        }
    }
</script>
</body>
</html>
